function BindList_Admin() {
	FindByDeptIdPaging_admin(
			CurrentDeptId,
			function(ppData) {
				if (ppData != null) {
					var mmData = eval(ppData);
					var result = mmData.result;
					var data = mmData.resultContent;
					var mmAdminList = data;
					var mmHtml = "";
					if (result == "1") {
						if(mmAdminList.length==0){
							mmHtml += "<div style='text-align:center;width:100%;'>查无数据</div>";
						}else{
							
						mmHtml = "<table id='AdminTable' class='table table-striped table-hover' width='100%'>";
						mmHtml += "<thead><tr>";
						mmHtml += "<th style='text-align:ce" +
								"nter;'>序号</th>";
						mmHtml += "<th style='text-align:center;'>姓名</th>";
						mmHtml += "<th style='text-align:center;'>登录账号</th>";
						mmHtml += "<th style='text-align:center;'>登录密码</th>";
						mmHtml += "<th style='text-align:center;'>手机号</th>";
						mmHtml += "<th style='text-align:center;'>管理员权限</th>";
						mmHtml += "<th style='text-align:center;'>是否有效</th>";
						mmHtml += "<th style='text-align:center;'>操作</th>";
						mmHtml += "</tr></thead>";
						mmHtml += "<tbody>";
						
						
						
							for (var i = 0; i < mmAdminList.length; i++) {

								var mmAdminId = mmAdminList[i].adminid;
								var mmTruename = mmAdminList[i].truename;
								var mmLoginname = mmAdminList[i].loginname;
								var mmLoginpassword = mmAdminList[i].loginpassword;
								var mmPhone = mmAdminList[i].phone;
								var mmAdmintype = mmAdminList[i].admintype;
								var mmIsvalid = mmAdminList[i].isvalid;
								
								

								if (mmIsvalid == 1) {
									mmIsvalid = "<span style='color:green;font-size:14px;font-weight:bold;  font-family:微软雅黑;'>√</span>";
								} else {
									mmIsvalid = "<span style='color:red;font-size:14px;font-weight:bold;font-family:微软雅黑;'>×</span>";
								}
								if (mmAdmintype == 2) {
									mmAdmintype = "录入";
								} else {
									mmAdmintype = "查阅";
								}

								mmHtml += "<tr style='height:77px;' id=Admin" + mmAdminId + "> ";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + (i + 1) + "</td>";
								
								mmHtml += "<td style='text-align:center;vertical-align:middle;' align='left'>" + mmTruename + "</a></td>";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmLoginname + "</td>";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmLoginpassword + "</td>";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPhone + "</td>";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmAdmintype + "</td>";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmIsvalid + "</td>";
								mmHtml += "<td style='text-align:center;vertical-align:middle;'><button type='button' class='btn btn-primary' onclick=\"PrepareToModify_Admin('"+ mmAdminId+ "');\" style=\"margin-right: 5px;\">修改</button><button type='button' class='btn btn-danger' onclick=\"ToDelete_Admin('"
										+ mmAdminId + "');\">删除</button></td></tr>";
							}
							mmHtml += "</tbody></table>";
							
						}
						$("#ListPart_admin").html(mmHtml);
							if(CurrentDeptId!=null){

								var mmHtml2 = "<a href='../admin/admin_huizongbiao_by_deptid?deptid="+CurrentDeptId+"'><span class=\"btn btn-info\" style=\"float:right;margin-right:15px;margin-top:10px;\">导出选中单位管理员</span></a>";
								$("#daochudanweiguanliyuan").html(mmHtml2);
							}
					}
				}
			});
}


function PrepareToAdd_Admin() {
	//$("#ActionText_admin").html("管理员添加");
	ClearForm_Admin();
	ShowOrHideAdminListPart(false);
	ShowOrHideAdminEditPart(true);
	$(".SaveButton_Admin").unbind();
	$(".SaveButton_Admin").bind("click", ToAdd_Admin);
}

function ToAdd_Admin() {
	GetInputAndCheck_Admin(function(ppMessage) {
	}, function(ppDataObject) {
		Add_admin(ppDataObject, function(ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var result = mmData.result;
				var data = mmData.resultContent;
				var message = mmData.message;
				if (result == "1") {
					if (confirm("添加成功，是否返回列表？")) {
						ClearForm_Admin();
						CurrentNewsAdminId = data.adminid;
						SelectCurrentOfActionType('4');
					} else {
						ClearForm_Admin();
					}
				} else {
					alert(message);
				}
			}
		});
	});
}

function PrepareToModify_Admin(ppAdminId) {
	CurrentNewsAdminId = ppAdminId;
	ShowOrHideAdminListPart(false);
	ShowOrHideAdminEditPart(true);
	ClearForm_Admin();
	BindOldValue_Admin(ppAdminId);
	$(".SaveButton_Admin").unbind();
	$(".SaveButton_Admin").bind("click", ToModify_Admin);
}

function BindOldValue_Admin(ppAdminId) {
	FindCustomOne_admin(ppAdminId, function(ppData) {
		if (ppData != null) {
			var mmData = eval(ppData);
			var result = mmData.result;
			var message = mmData.message;
			var data = mmData.resultContent;
			if (result == "1") {
				CurrentDeptId = data.deptid;
				$("#adminid").val(data.adminid);
				$("#loginname").val(data.loginname);
				$("#loginpassword").val(data.loginpassword);
				$("#truename").val(data.truename);
				$("#phone").val(data.phone);
				$("#admintype").val(data.admintype);
				$("#isvalid").val(data.isvalid);
				if (data.admintype == "2") {
					$("#checkpass").prop({checked:true});
				} else {
					$("#checkpass").prop({checked:false});
				}
				if (data.isvalid == "1") {
					$("#checkpass").prop({checked:true});
				} else {
					$("#checkpass").prop({checked:false});
				}
				
			} else {
				alert(message);
			}
		} else {
			alert("绑定失败");
		}
	});
}

function ToModify_Admin() {
	GetInputAndCheck_Admin(function(ppMessage) {
	}, function(ppDataObject) {
		Modify_admin(ppDataObject, function(ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var result = mmData.result;
				var message = mmData.message;
				if (result == "1") {
					alert("修改成功");
					ClearForm_Admin();
					SelectCurrentOfActionType('4');
				} else {
					alert(message);
				}
			}
		});
	});
}

function ToDelete_Admin(ppAdminId) {
	if (confirm("确定要删除吗？")) {
		Delete_admin(ppAdminId,function(ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var message = mmData.message;
				var result = mmData.result;
				var data = mmData.resultContent;
				if (result == "1") {
					alert(data);
					SelectCurrentOfActionType('4');
				} else {
					alert(message);
				}
			}
		});
	}
}


function GetInputAndCheck_Admin(ppErrorCallback, ppSuccessCallback) {
	var mmDataObject = new Object();

	var mmAdminId = $("#adminid").val();
	var mmLoginname = $("#loginname").val();
	var mmLoginpassword = $("#loginpassword").val();
	var mmTruename = $("#truename").val();
	var mmPhone = $("#phone").val();
	var mmAdmintype = $("#admintype").is(":checked") ? "2" : "3";
	var mmIsvalid = $("#isvalid").is(":checked") ? "1" : "0";
	
	if (mmLoginname == "") {
		alert("请填写登录账号");
		$("#loginname").focus();
		return false;
	}
	if (mmLoginpassword == "") {
		alert("请填写密码");
		return false;
	}
	if (mmTruename == "") {
		alert("请填写姓名");
		return false;
	}
	
	mmDataObject.deptid = CurrentDeptId;
	mmDataObject.adminid = mmAdminId;
	mmDataObject.loginname = mmLoginname;
	mmDataObject.loginpassword = mmLoginpassword;
	mmDataObject.truename = mmTruename;
	mmDataObject.phone = mmPhone;
	mmDataObject.admintype = mmAdmintype;
	mmDataObject.isvalid = mmIsvalid;
	ppSuccessCallback(mmDataObject);
}

function ClearForm_Admin() {
	$("#adminid").val("");
	$("#loginname").val("");
	$("#loginpassword").val("");
	$("#truename").val("");
	$("#phone").val("");
	
}

